<template>
  <div>
    <div class="containe">
      <div class="search-section">
        <div class="search-group">
          <label for="material-order">关联工单号：</label>
          <el-input type="text" clearable v-model="formData.docNo" @keyup.enter="handleSearch" />
        </div>
        <div class="search-group">
          <label for="associated-order">领料单：</label>

          <el-input type="text" clearable v-model="formData.planNo" @keyup.enter="handleSearch" />
        </div>
        <div class="search-group">
          <el-button @click="handleSearch">
            <Icon icon="ep:search" class="mr-5px" />
            搜索
          </el-button>
        </div>
      </div>
    </div>
    <MaterialRecordForm
      :planNo="formData.planNo"
      :docNo="formData.docNo"
      type="true"
      ref="reference"
    />
  </div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import MaterialRecordForm from '../materialplan/components/MaterialRecordForm.vue'

const formData = reactive({
  docNo: '',
  planNo: ''
})

const route = useRoute()
onMounted(() => {
  console.log('路由参数', route.query)
  formData.docNo = route.query.docNo
  formData.planNo = route.query.planNo
  if (route.query.docNo) {
    handleSearch()
  }
})

const reference = ref(null)

const handleSearch = async () => {
  //reference.value.getList1({ docNo: formData.docNo, planNo: formData.planNo })
  await reference.value.getList1({
    docNo: formData.docNo,
    planNo: formData.planNo
  })
  // 判断接口返回数据是否为空
  // 直接访问子组件的 materialLs
  if (!reference.value.materialLs.length) {
    ElMessage.warning('该工单/领料单没有领料信息')
  }
}
</script>
<style scope lang="less">
.containe {
  margin-bottom: 20px;
  background-color: #fff;
  padding: 20px;
  width: 100%;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;

  .tit {
    font-size: 18px;
  }

  .user-info {
    display: flex;
    align-items: center;

    .logout-btn {
      margin-left: 10px;
    }
  }
}

.search-section {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-bottom: 20px;
  margin-left: 20px;
  color: #666;
}

.search-group {
  display: flex;
  align-items: center;
}

.search-group label {
  margin-right: 10px;
  white-space: nowrap;
}

.search-input {
  position: relative;
}

.search-input input {
  width: 200px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.search-input .search-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
}

.search-btn {
  padding: 8px 20px;
  background-color: #1890ff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.search-btn:hover {
  background-color: #40a9ff;
}
</style>
